<?php
    
        include('confdb.php');

        $num = "SELECT * FROM connect";
        $numer = mysqli_query($conn, $num);
        $queryKort = "SELECT count(*) as countKort from connect" ;
        $resultKort = mysqli_query($conn, $queryKort);
        $rowKort = mysqli_fetch_array($resultKort);
        $otvet['countKort'] = $rowKort['countKort'];

        $otvet['kort'] =array();

        while ($kol_kort = mysqli_fetch_array($numer)) {
            
            $ocenki = array();
            
            $ocenki['ids'] = $kol_kort['idconnect'];
            $ocenki['kol'] = $kol_kort['kol_sud'];
            $ocenki['nomer_kort'] = $kol_kort['nomer_kort'];
            $ocenki['sys'] = $kol_kort['sys'];
            $query = "SELECT count(*) as test FROM connect_judges where connect_idconnect = ".$kol_kort['idconnect'];
            $result = mysqli_query($conn, $query);
            $row = mysqli_fetch_array($result);
            $ocenki['kol_sud'] = $row['test'] ?? 0;

            array_push($otvet['kort'], $ocenki);
            
        }

        $otvet['success'] = 1;


        echo json_encode($otvet);

?>